package com.mmd.manage.web;

import com.mmd.bean.CODE;
import com.mmd.bean.WebJsonBean;
import com.mmd.common.entity.MmdProduct;
import com.mmd.manage.service.ProductService;
import com.mmd.manage.vo.MmdProductPageEo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/api/product")
@Api(tags = "产品库接口")
public class ProductController {

    @Autowired
    private ProductService productService;

    @RequestMapping("/getCustomProductPageList")
    @ApiOperation(value = "分页获取产品信息列表")
    @ResponseBody
    public WebJsonBean getCustomProductPageList(MmdProductPageEo mmdProductPageEo){
        return new WebJsonBean(CODE.SUCCESS, productService.getMmdProductPageList(mmdProductPageEo));
    }

    @RequestMapping("/getCustomProductDetail")
    @ApiOperation(value = "获取产品详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键ID", required = true, dataType = "string"),
    })
    @ResponseBody
    public WebJsonBean getCustomProductDetail(Long id){
        return new WebJsonBean(CODE.SUCCESS, productService.getMmdProductById(id));
    }

    @RequestMapping("/addCustomProduct")
    @ApiOperation(value = "新增产品信息")
    @ResponseBody
    public WebJsonBean addCustomProduct(MmdProduct mmdProduct){
        productService.addMmdProduct(mmdProduct);
        return new WebJsonBean(CODE.SUCCESS);
    }

    @RequestMapping("/modifyCustomProduct")
    @ApiOperation(value = "修改产品信息")
    @ResponseBody
    public WebJsonBean modifyCustomProduct(MmdProduct mmdProduct){
        productService.modifyMmdProduct(mmdProduct);
        return new WebJsonBean(CODE.SUCCESS);
    }

    @RequestMapping("/deleteCustomProduct")
    @ApiOperation(value = "删除产品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键ID", required = true, dataType = "string"),
    })
    @ResponseBody
    public WebJsonBean deleteCustomProduct(Long id){
        productService.deleteMmdProduct(id);
        return new WebJsonBean(CODE.SUCCESS);
    }
}
